package com.song.invoicing.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.song.invoicing.mapper.SaleRecordMapper;
import com.song.invoicing.pojo.dao.PurchaseRecord;
import com.song.invoicing.pojo.dto.SaleQueryDTO;
import com.song.invoicing.service.SaleRecordService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@RequiredArgsConstructor
public class SaleRecordServiceImpl implements SaleRecordService {
     private final SaleRecordMapper saleRecordMapper;
    @Override
    public Map<String, Object> getSaleRecords(SaleQueryDTO saleQueryDTO) {
        PageHelper.startPage(saleQueryDTO.getPage(),saleQueryDTO.getPageSize());
        Page<PurchaseRecord> page = saleRecordMapper.getSaleRecords(saleQueryDTO);
        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("total",page.getTotal());
        resultMap.put("list",page.getResult());
        return resultMap;
    }
}
